//
//  JPAPIDefaultManager.m
//  JPWords
//
//  Created by 梁淑婷 on 2024/4/20.
//

#import "JPAPIDefaultManager.h"

@implementation JPAPIDefaultManager

- (instancetype)init{
    if (!(self = [super init])) return self;
    
    self.paramSource = self;
    self.validator = self;
    
    return self;
}

#pragma mark - JPAPIManager
- (NSString *)methodName
{
    NSAssert(NO, @"子类重写");
    return @"";
}

- (NSString *)serviceIdentifier{
    return JPNetworkingApiServiceIdentifier;
}

- (JPAPIManagerRequestType)requestType
{
    return JPAPIManagerRequestTypePOST;
}

#pragma mark - JPAPIManagerParamSource
- (NSDictionary *)paramsForApi:(JPAPIBaseManager *)manager{
    return @{};
}

#pragma mark - JPAPIManagerValidator
/**
 校验请求参数
 */
- (JPAPIManagerErrorType)manager:(JPAPIBaseManager *)manager isCorrectWithParamsData:(NSDictionary *)data{
    return JPAPIManagerErrorTypeNoError;
}

/**
 校验请求参数
 */
- (JPAPIManagerErrorType)manager:(JPAPIBaseManager *)manager isCorrectWithCallBackData:(NSDictionary *)data{
    NSNumber *code = data[@"code"];
    if (code && code.integerValue == 0){
        return JPAPIManagerErrorTypeNoError;
    }else if (code && code.integerValue == 401){
        return JPAPIManagerErrorTypeNeedLogin;
    }
    return JPAPIManagerErrorTypeParamsError;
}

@end
